package api.model;

import m.common.model.FieldMeta;
import m.common.model.LinkTableMeta;
import m.common.model.TableMeta;
import m.common.model.type.FieldType;
import m.common.model.util.ModelQueryList;
import m.common.model.util.QueryCondition;
import m.system.cache.FlushCache2;
import manage.model.StatusModel;

import java.util.List;

@TableMeta(name="ot_api_auth_inter",description="鉴权接口")
public class ApiAuthInter extends StatusModel implements FlushCache2 {
    @LinkTableMeta(name="auth_oid",table= ApiAuthinfo.class,description="所属鉴权")
    private ApiAuthinfo auth;

    @FieldMeta(name="name",type= FieldType.STRING,length=100,description="名称|小写英文或下划线")
    private String name;
    @FieldMeta(name="description",type=FieldType.STRING,length=1000,description="描述")
    private String description;

    @FieldMeta(name="type",type=FieldType.STRING,length=10,description="类型",dictOption = "A:导入,B:查询")
    private String type;
    @LinkTableMeta(name="model_table_oid",table= ApiTable.class,description="接口模型|TABLE，自建类型的表")
    private ApiTable modelTable;
    @FieldMeta(name="sub_table",type=FieldType.STRING,length=500,description="扩展属性")
    private String[] subTables;
    @FieldMeta(name="data_handler",type=FieldType.STRING,length=500,description="数据处理")
    private String[] dataHandler;

    public String[] getDataHandler() {
        return dataHandler;
    }

    public void setDataHandler(String[] dataHandler) {
        this.dataHandler = dataHandler;
    }

    public ApiAuthinfo getAuth() {
        return auth;
    }

    public void setAuth(ApiAuthinfo auth) {
        this.auth = auth;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public ApiTable getModelTable() {
        return modelTable;
    }

    public void setModelTable(ApiTable modelTable) {
        this.modelTable = modelTable;
    }

    public String[] getSubTables() {
        return subTables;
    }

    public void setSubTables(String[] subTables) {
        this.subTables = subTables;
    }

    @Override
    public ApiAuthInter getCacheModel(String authId, String name) throws Exception {
        List<ApiAuthInter> ls= ModelQueryList.getModelList(ApiAuthInter.class,new String[]{"*","auth.authId","modelTable.*"},null,
                QueryCondition.and(QueryCondition.eq("auth.authId",authId),QueryCondition.eq("name",name)));
        return !ls.isEmpty() ?ls.get(0):null;
    }
}
